package com.ruicar.afs.cloud.finance.common.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.ruicar.afs.cloud.common.mq.finance.debit.dto.FinanceBusinessAccountingDto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Date;

/**
 * <p>Description: </p>
 *
 * @author ZC.GUO
 * @version 1.0
 * @date create on 2020-07-02 09:38
 */
@Data
@Accessors(chain = true)
@TableName(value ="finance_business_accounting", autoResultMap = true)
public class FinanceBusinessAccounting {
    @ApiModelProperty("唯一标识")
    @JsonSerialize(
            using = ToStringSerializer.class
    )
    @JSONField(
            serializeUsing = com.alibaba.fastjson.serializer.ToStringSerializer.class
    )
    @TableId(
            value = "id",
            type = IdType.ASSIGN_ID
    )
    private Long id;
    /** 业务操作id */
    private Long transId ;
    /** 费用类型;利息收入、准备金 */
    private String feeType ;
    /** 费用来源表 */
    private String feeSourceTable ;
    /** 金额 */
    private BigDecimal amount ;
    /** 付款账号 */
    private String payAccount ;
    /** 收款账号 */
    private String receiptAccount;
    @ApiModelProperty("创建者")
    @TableField(
            fill = FieldFill.INSERT
    )
    private String createBy;
    @JsonFormat(
            timezone = "GMT+8",
            pattern = "yyyy-MM-dd HH:mm:ss"
    )
    @DateTimeFormat(
            pattern = "yyyy-MM-dd HH:mm:ss"
    )
    @ApiModelProperty("创建时间")
    @TableField(
            fill = FieldFill.INSERT
    )
    private Date createTime;
    @ApiModelProperty("更新者")
    @TableField(
            fill = FieldFill.UPDATE
    )
    private String updateBy;
    @JsonFormat(
            timezone = "GMT+8",
            pattern = "yyyy-MM-dd HH:mm:ss"
    )
    @DateTimeFormat(
            pattern = "yyyy-MM-dd HH:mm:ss"
    )
    @ApiModelProperty("更新时间")
    @TableField(
            fill = FieldFill.UPDATE
    )
    private Date updateTime;

    public static FinanceBusinessAccounting convertFromInfo(FinanceBusinessAccountingDto financeBusinessAccountingDto) {
        FinanceBusinessAccounting financeBusinessAccounting = new FinanceBusinessAccounting();
        financeBusinessAccounting.setAmount(financeBusinessAccountingDto.getAmount());
        financeBusinessAccounting.setFeeSourceTable(financeBusinessAccountingDto.getFeeSourceTable());
        financeBusinessAccounting.setFeeType(financeBusinessAccountingDto.getFeeType());
        financeBusinessAccounting.setReceiptAccount(financeBusinessAccountingDto.getReceiptAccount());
        financeBusinessAccounting.setPayAccount(financeBusinessAccountingDto.getPayAccount());
        financeBusinessAccounting.setTransId(financeBusinessAccountingDto.getTransId());
        return financeBusinessAccounting;
    }

}
